package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Address;
import io.swagger.v3.oas.annotations.media.Schema;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Schema(description ="地址表")
@Mapper
public interface AddressMapper {
    @Schema(description ="添加地址")
    @Insert("insert into address(addressId,buyerId,address,phone,name) values (#{addressId},#{buyerId},#{address},#{phone},#{name})")
    boolean add(Address address);

    @Schema(description ="删除地址")
    @Delete("delete from address where addressId=#{addressId}")
    boolean delete(String addressId);

    @Schema(description ="根据地址id查询地址")
    @Select("select * from address where addressId=#{addressId}")
    Address findById(String addressId);

    @Schema(description ="更新地址")
    @Update("update address set address=#{address},phone=#{phone},name=#{name} where addressId=#{addressId}")
    boolean update(Address address);

    @Schema(description ="根据用户id查询地址")
    @Select("select * from address where buyerId=#{buyerId}")
    ArrayList<Address> findByUserId(String userId);

    /*@Schema(description ="根据用户id更新地址")
    @Update("update address set address=#{address},phone=#{phone} where userId=#{userId}")
    boolean updateByUserId(Address address);*/

    @Schema(description ="根据用户id删除地址")
    @Delete("delete from address where buyerId=#{buyerId}")
    boolean deleteByUserId(String userId);


}
